package com.knxhd.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * 利用Spark统计文件中单词出现的频次
 *
 * @Classname WordCount
 * @Date 2023/10/29 09:57
 * @author tianluhua
 */
object WordCount {

  def main(args: Array[String]): Unit = {
    // 连接Spark
    val sparkConfig = new SparkConf().setMaster("local").setAppName("WordCount")
    val context = new SparkContext(sparkConfig)
    try {
      // 执行业务流程
      // 1. 读取文件
      val lines:RDD[String] = context.textFile("data")

    } catch {
      case ex: Exception => {
        ex.getCause
      }
    } finally {

      // 关闭连接
      context.stop()
    }

  }
}
